<template>
  <table-content />
</template>
<script setup>
import { toRaw, onMounted } from 'vue'
import TableToolbar from './table-toolbar.vue'
import TableContent from './table-content.vue'
import TransferBar from './transfer-bar.vue'
import DownloadBar from './download-bar.vue'
import TagBar from './tag-bar.vue'
import {
  useColumns,
  useRowSelection,
  useRowSelectionActive,
} from './provide-context.js'
/**
 * 列
 */
let columns = useColumns()
columns.value = [
  {
    title: '名称',
    dataIndex: 'dataName',
    key: 'dataName',
    fixed: 'left',
    width: 200,
    sorter: true,
    showSorterTooltip: {
      title: '按首字母排序',
    },
    // sortDirections: ['name-descend', 'name-ascend'],
  },
  {
    title: '文件类型',
    dataIndex: 'fileType',
    key: 'fileType',
    width: 150,
    sorter: true,
    showSorterTooltip: {
      title: '按首字母排序',
    },
    // // sortDirections: ['descend', 'ascend'],
    // filters: [
    //   { text: '文件类型1', value: '1' },
    //   { text: '文件类型2', value: '2' },
    //   { text: '文件类型3', value: '3' },
    // ],
    // filterMultiple: false,
    // filteredValue: null,
  },
  {
    title: '编码',
    dataIndex: 'fileCode',
    key: 'fileCode',
    width: 250,
    checked: false,
  },
  {
    title: '上传时间',
    dataIndex: 'gmtCreate',
    key: 'gmtCreate',
    width: 180,
    sorter: true,
    checked: false,
    // sortDirections: ['descend', 'ascend'],
  },
  {
    title: '版本',
    dataIndex: 'version',
    key: 'version',
    width: 100,
    sorter: true,
    // sortDirections: ['descend', 'ascend'],
  },
  {
    title: '修改时间',
    dataIndex: 'updatedTime',
    key: 'updatedTime',
    width: 180,
    sorter: true,
    // sortDirections: ['descend', 'ascend'],
  },
  {
    title: '状态',
    dataIndex: 'dataStatus',
    key: 'dataStatus',
    width: 100,
    filters: [
      { text: '已发布', value: 'publish' },
      { text: '占用', value: 'occupy' },
    ],
    filterMultiple: false,
    filteredValue: null,
  },
  {
    title: '备注',
    dataIndex: 'note',
    key: 'note',
    width: 200,
  },
  {
    title: '文件大小',
    dataIndex: 'fileSizeShow',
    key: 'fileSizeShow',
    width: 150,
    sorter: true,
    // sortDirections: ['descend', 'ascend'],
    showSorterTooltip: {
      title: '按大小排序',
    },
  },
  // {
  //   title: '操作',
  //   dataIndex: 'operation',
  //   key: 'operation',
  //   fixed: 'right',
  //   width: 120,
  // },
].map(item => ({ ...item, checked: true }))
/**
 * 多选
 */

let rowSelection = useRowSelection()
rowSelection.getCheckboxProps = record => ({
  disabled: record.dataType === 'folder' || record.dataStatus === 2,
})
let rowSelectionActive = useRowSelectionActive()
rowSelectionActive.value = true

// onMounted(() => {
window.getSelectedFileId = function () {
  return JSON.stringify(
    (rowSelection?.selectedRowInfos?.value || []).map(toRaw),
  )
}
window.clearSelectedFileId = function () {
  rowSelection.selectedRowKeys.value = []
}
// })
</script>
<style lang="less" scoped>
.table {
  height: 100%;
  display: flex;
  flex-direction: column;
  .content {
    flex: 1;
    overflow: hidden;
    margin-top: 16px;
  }
}
</style>
